<div class="col-md-9">
  <div class="thumbnail">
    <!-- breadcrumb -->
    <ol class="breadcrumb breadcrumb-arrow">
      <li><a href="{:U(GROUP_NAME . '/Rbac')}">RBAC</a></li>
      <li><a href="{:U(GROUP_NAME . '/Rbac/user')}">用户列表</a></li>
      <li class="active"><span>配置用户角色</span></li>
    </ol>

    <table class="table">
      <caption>
        <h3>用户：{$user.p_name}　现有角色</h3>
        <h5 class="text-left"><a href="{:U(GROUP_NAME . '/Rbac/user')}" class="btn btn-info">返回</a></h5>
      </caption>
      <thead>
        <tr>
          <th>编号</th>
          <th>名称</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <volist name="roleUser" id="ru">
          <tr>
            <td>{$ru.role_id}</td>
            <td>{$ru.name}</td>
            <td>
              <form action="{:U(GROUP_NAME . '/Rbac/delRoleUser')}" method="post">
                <input type="hidden" name="roleUser" value="{$ru.role_id}_{$user.p_id}">
                <input type="submit" class="btn btn-danger" value="删除">
              </form>
            </td>
          </tr>
        </volist>
      </tbody>
    </table>
  </div>
  <div class="thumbnail">
    <h3 class="text-center">添加用户角色</h3>
    <form class="form-horizontal" role="form" method="post" action="{:U(GROUP_NAME . '/Rbac/modifyUserRole')}">
      <input type="hidden" name="p_id" value="{$user.p_id}">
      <!-- 所属角色 -->
      <div class="form-group" id="add-role-group">
        <label for="title" class="col-sm-2 control-label">所属角色</label>
        <div class="col-sm-7">
          <input type="button" class="btn" id="add-role" value="添加一个角色">
          <select class="form-control" id="select" name="role_id[]">
            <volist name="role" id="r">
              <option value="{$r.id}">{$r.name}({$r.remark})</option>
            </volist>
          </select>
        </div>
      </div>

      <div class="form-group" id="last">
        <br>
        <div class="col-sm-offset-2 col-sm-10">
          <a href="{:U(GROUP_NAME . '/Rbac/userRole', array('id' => $user['p_id']))}">取消添加</a>
          <button type="submit" class="btn btn-primary">保存添加</button>
        </div>
      </div>
    </form>
  </div>
</div>

<script>
  $(function () {
    $('#add-role').click(function () {
      var obj = $('#add-role-group').clone();
      obj.find('#add-role').remove();
      $('#last').before(obj);
    });
  });
</script>